<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>用户列表</title>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/themes/default/easyui.css"/>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/themes/icon.css"/>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/demo.css"/>
	<script src="${pageContext.request.contextPath }/plugins/jQuery/jquery.min.js"></script>
	<script src="${pageContext.request.contextPath }/plugins/jQuery/jquery.easyui.min.js"></script>
	<script type="text/javascript">
		$(function(){
			// 站点类型下拉列表
			$('#stationKind').combobox({
				valueField:'value',
				textField:'text',
				data:[{"value":"-1","text":"全部站点类型"},
					{"value":"1","text":"提货仓"},
					{"value":"2","text":"中心仓"}
				]
			});
			$('#stationKind').combobox("setValue",-1);
			
			// 站点属性下拉列表
			$('#stationProperty').combobox({
				valueField:'dict_code',
				textField:'dict_name',
				url:'${pageContext.request.contextPath }/admin/station/findStationProperty'
			});
			$('#stationProperty').combobox("setValue",'-1');
			
			loadTable();
			$('#dlg').dialog('close');
			
		});
		
		function loadTable(){
			$('#dg').datagrid({
				rownumbers:true,
				singleSelect:true,
				pagination:true,
				pageSize:10,
				pageList:[10,20,30,50,100],
		 		url:'${pageContext.request.contextPath }/admin/station/listStation',
		 		queryParams:{
		 			 stationKind:$('#stationKind').combobox("getValue"),
		 			 stationName:$('#stationName').val(),
		 			 stationMaster:$('#stationMaster').val(),
		 			 stationProperty:$('#stationProperty').combobox("getValue")
		 		},
	    		columns:[[
					{field:'station_id',title:'编号',align:'center',width:45},
					{field:'station_name',title:'站点名称',align:'center',width:110},
					{field:'station_address',title:'站点地址',align:'center',width:80},
					{field:'charge_name',title:'区域负责人',align:'center',width:70},
					{field:'master_name',title:'站长姓名',align:'center',width:70},
					{field:'init_password',title:'通用初始密码',align:'center',width:90},
					{field:'send_time',title:'需到货时间',align:'center',width:100},
					{field:'img_url',title:'站长头像',width:100,align:'center',formatter: function (value, row, index) {
						var res="";
						if(value==null || value==''){
							res="<span style='color:red'>暂未上传</span>";
						}else{
							res= '<a href="javascript:showImg(\''+value+'\')" name="show" class="easyui-linkbutton" ></a>';
						}
						return res;
					}},
					{field:'report_phone',title:'站点投诉电话',width:90,align:'center'},					
					{field:'station_kind',title:'站点类型',width:60,align:'center',formatter: function (value, row, index) {
						var status='';
						if(value==1)
							status="提货仓";
						else if(value==2)
							status="中心仓";
						return status;
					}},
					{field:'property_name',title:'站长市场属性',width:100,align:'center'},
					{field:'create_time',title:'站点创建时间',width:130,align:'center'},
					{field:'operation',title:'操作选项',width:220,align:'center',formatter: function (value, row, index) {
						var str = '<a href="javascript:edit('+row.station_id+')" name="edit" class="easyui-linkbutton" ></a>';					
						str=str+' | <a href="javascript:remove('+row.station_id+')" name="remove"  class="easyui-linkbutton" ></a>';
						str=str+' | <a href="javascript:addCustomer('+row.station_id+')" name="addPerson"  class="easyui-linkbutton" ></a>';
						return str;
					}}
	 			]],
				onLoadSuccess:function(data){  
			        $("a[name='edit']").linkbutton({text:'编辑',plain:true,iconCls:'icon-edit'});
			        $("a[name='remove']").linkbutton({text:'删除',plain:true,iconCls:'icon-my-minus'});  
			        $("a[name='addPerson']").linkbutton({text:'添加客户',plain:true,iconCls:'icon-person-add'});  
			        $("a[name='manage']").linkbutton({text:'管理',plain:true,iconCls:'icon-my-manage'});   
			        $("a[name='show']").linkbutton({text:'查看',plain:true,iconCls:'icon-search'});
				}
			});
		}
		
		function addCustomer(sid){
			show("${pageContext.request.contextPath}/admin/customer/addBefore/"+sid,"新增客户信息","icon-person-add");
		}
		
		function remove(stationid){
			$.messager.confirm('Confirm', '该操作谨慎操作！一旦删除，不可恢复！您确认要删除该站点吗?', function(r){
				if (r){
					$.post("${pageContext.request.contextPath}/admin/station/remove",{stationid:stationid},
					function(data){
						if(data=="1"){
							$.messager.alert('系统消息','站点删除成功！');
							$('#dg').datagrid('reload');  
						}else{
							$.messager.alert('系统消息','站点删除失败！');
						}
							
					},"text");
					
				}else{
					$.messager.alert('系统消息','删除操作取消！');
				}
			});
		}

		function showImg(imgUrl){
			$('#dlg').dialog('open');
			var image=document.getElementById("stationImg");
			var src=imgUrl;
			image.setAttribute("src",src );
		}
		
		function edit(stationid){
			show("${pageContext.request.contextPath}/admin/station/editBefore/"+stationid,"修改站点信息","icon-edit");
			
		}
		// 重置密码功能，重置的密码为随机生成的6位数字
		function resetPass(userid){
			var pass=getRandomPass();
			$.post("${pageContext.request.contextPath}/admin/user/resetPass",{userid:userid,password:pass},
				function(data){
					if(data=="0"){
						$.messager.alert('系统消息','<span style=\"color:red;\">密码重置失败，请稍后再试！</span>');	 
					}else{
						$.messager.alert('系统消息','密码重置成功！<br/>重置后的密码为：'+pass);
						$('#dg').datagrid('reload'); 
					}
						
				},"text");
		}
		

		// 打开一个新的选项卡，并制定选项卡的名称
		function show(url,name){
			parent.window.addTab(name,url);
		}
		
		function show(url,name,icon){
			parent.window.addTab(name,url,icon);
		}
		
		function findData(){
			loadTable();
		}
		
		function doAddNotice(){
			show("${pageContext.request.contextPath}/admin/station/addBefore","新增站点信息","icon-my-add");
		}

	</script>
	<style type="text/css">
		body{
		font-family:'微软雅黑';}
	</style>
  </head>
  
  <body>
    <table id="dg" title="站点列表" style="width:1320px;height:455px" toolbar="#searchtool"></table>
    <div id="searchtool" style="padding:5px">  
       <span style="margin:0px 12px;">站点类型:</span><input id="stationKind" class="easyui-textbox" style="width:180px;height:26px"/> 
       <span style="margin:0px 12px;">市场属性:</span><input id="stationProperty" class="easyui-textbox" style="width:180px;height:26px"/> 
       <span style="margin:0px 12px;">站点名称:</span><input id="stationName" class="easyui-textbox" style="width:180px;height:26px"/> 
       <span style="margin:0px 12px;">站长姓名:</span><input id="stationMaster" class="easyui-textbox" style="width:80px;height:26px"/> 
       <a href="javascript:findData()" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:100px;margin:0px 3px;">查询</a> 
       <a href="javascript:doAddNotice()" class="easyui-linkbutton" data-options="iconCls:'icon-my-add'" style="width:100px;margin:0px 3px;">新增站点</a> 
    </div>
    <div id="dlg" class="easyui-dialog" title="站长头像查看" style="width:270px;height:390px;max-width:800px;padding:10px" data-options="
			onResize:function(){
				$(this).dialog('center');
			}">
			<img id="stationImg" src="" width="220" height="320"/>
	</div>
  </body>
</html>
